var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:'',
    phone:'',
    address:'',
    cardName:'',
    productNum:'',
    procuctPrice:'',
    createDate:'',
    orderMoney:'',
    picture:"",
    orderState:'',
    ordernNum:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var orderNum = options.orderNum;
    var that = this

    wx.getStorage({
      key: 'openid',
      success: function(res) {
        let openid = res.data

        wx.request({
          url: app.globalData.URL + '/app/awardLogic/proDetail?ordernNum=' + orderNum+ '&openid=' + openid,
          success: function (res) {
            console.log(res)
            that.setData({
              name: res.data.order.name,
              phone: res.data.order.phone,
              address: res.data.order.address,
              cardName: res.data.order.cardName,
              productNum: res.data.order.productNum,
              procuctPrice: res.data.order.procuctPrice,
              createDate: res.data.order.createDate,
              orderMoney: res.data.order.orderMoney,
              picture: res.data.order.picture,
              orderState: res.data.order.orderState,
              ordernNum: res.data.order.ordernNum
            })
          }
        }) 
      },
    })
    
  },
  confirmOrder:function(){
    var that = this

    wx.getStorage({
      key: 'openid',
      success: function(res) {
        let openid = res.data

        wx.request({
          url: app.globalData.URL + '/app/awardLogic/qddl?orderNum=' + that.data.ordernNum + '&openid='+ openid,
          success: function (res) {
            console.log(res)
            if (res.data.flag == true) {
              wx.showToast({
                title: '确认成功',
                duration:5000,
                success: function () {
                  wx.navigateBack({

                  })
                }
              })
            }
          }
        })
      },
    })
    
  },
  confirmMoney:function(){
    var that = this
    if(that.data.picture){
      wx.getStorage({
        key: 'openid',
        success: function (res) {
          let openid = res.data

          wx.request({
            url: app.globalData.URL + '/app/awardLogic/qdsk?orderNum=' + that.data.ordernNum + '&openid=' + openid,
            success: function (res) {
              console.log(res)
              if (res.data.flag == true) {
                wx.showToast({
                  title: '确认成功',
                  duration: 5000,
                  success: function () {
                    wx.navigateBack({

                    })
                  }
                })
              }
            }
          })
        },
      })
    }else{
      wx.showModal({
        title: '',
        content: '还没有上传凭证，不能收款',
      })
    }  
  }
  

  
})